package com.dgut.cbd.finalexp.dto;

import com.dgut.cbd.finalexp.entity.Record;
import lombok.Data;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @Program: demo
 * @Description:
 * @Author: cbd
 * @Create: 2021-06-27
 * @Version: 1.0.0
 **/
@Data
@ToString
public class RecordInfo {

    String id;
    @NotNull
    @NotBlank
    String stuId;

    @NotNull
    @NotBlank
    String name;

    @NotNull
    @NotBlank
    String phone;
    @NotNull
    @NotBlank
    String health;
    @NotNull
    @NotBlank
    String dangerPeopleContact;
    @NotNull
    @NotBlank
    String locationProvince;
    @NotNull
    @NotBlank
    String locationCity;
    @NotNull
    @NotBlank
    String locationVillage;

    @NotNull
    Double temperature;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @NotNull
    Date date;
    @NotNull
    @NotBlank
    String emergencyContactPhone;
    @NotNull
    @NotBlank
    String emergencyContactName;
    @NotNull
    @NotBlank
    String dangerAreaReach;
    @NotNull
    @NotBlank
    String dangerMark;

    public RecordInfo(){}

    public RecordInfo(Record record){

        if (record == null){
            return;
        }
        this.name=record.getName();
        this.stuId=record.getStuId();
        this.dangerMark = record.getDangerMark();
        this.dangerAreaReach = record.getDangerAreaReach();

        this.dangerPeopleContact = record.getDangerPeopleContact();
        this.health = record.getHealth();
        this.date=record.getDate();
        this.emergencyContactName = record.getEmergencyContactName();
        this.emergencyContactPhone = record.getEmergencyContactPhone();
        String[] nowLocation = record.getNowLocation().split("-");
        this.locationProvince = nowLocation[0];
        this.locationCity = nowLocation[1];
        this.locationVillage = nowLocation[2];
        this.temperature = record.getTemperature();
    }

}
